package com.hucheng.user.api.entity;

import com.hucheng.user.api.dto.UserDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-04-24
 * @Description: 持久层数据
 **/
@Data
public class UserDO extends BaseDO{
    private Integer userId;
    private String username;
    private String password;

    public static UserDO buildUserDO(final UserDTO userDTO) {
        if (userDTO != null) {
            UserDO userDO = new UserDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(userDTO.getUserId()+"")) {
                userDO.setUserId(userDTO.getUserId());
                userDO.setDateUpdated(currentTime);
            }else{
                userDO.setUsername(userDTO.getUsername());
                userDO.setDateCreated(currentTime);
            }
            userDO.setPassword(userDTO.getPassword());
            return userDO;
        }
        return null;
    }
}
